$(function(){
	// 上からビュっと出る奴いろいろ使えそう
    var element = $("#flashMessage");
    // アレを閉じる関数
    var close = function(){ 
    	element.slideUp(); 
    };
    // アレをビヨーンと表示
    element.slideDown();
    // アレがクリックされたら閉じる
    element.click(close);
    // 5秒後に勝手に閉じる
    setTimeout(close, 5000);
});

// 連想配列を作成する関数
function makearray(str){
	var data = {};
	str = str.replace("?","");
	var result = str.split("&");

	for(index in result){
		var tmp = result[index].split('=');
		data[tmp[0]] = tmp[1];
	}
	//console.log(data);
	
	return data;
}

function getAction(pathObj){
	var url = pathObj.hrefNoSearch;
	var action = url.replace(WEB_ROOT, '');
	action = action.replace(/&.+/,"");	//変数除去
	action.replace(/\/$/,"");			//最後の奴の除去
	return action;
}

function getPage(pathObj){
	var page = pathObj.split("?");
	return page[0];
}

function getTweetUnitByChild(child){
	var tmp = child.parent();
	while(true){
		var parent = tmp.parent();
		if(parent == undefined){ return null; }
		
		if(parent.attr("timeline-id")){
			return parent;
		}
		tmp = parent;
	}
}

function date(str){
	var d = new Date(str);
	var month = d.getMonth() + 1;
	if(isNaN(month) == true){
		return "";
	}
	var date = d.getDate();
	var minu = d.getMinutes();
	var sec = d.getSeconds();
	if (month < 10) { month = "0" + month; }
	if (date < 10) { date = "0" + date; }
	if (sec < 10) { sec = "0" + sec; }
	if (minu < 10) { minu = "0" + minu; }
	return month + '/' + date + ' ' + 
	       d.getHours() + ':' + minu + ':' + sec;
}

function p(str){
	console.log(str);
}

// 全ての文字列 s1 を s2 に置き換える
function replaceAll(expression, org, dest){
    return expression.split(org).join(dest);
}

function replaceLink(str){
	// urlをリンクに置き換える
	matches = str.match(/https?:\/\/[-_.!~*¥'()a-zA-Z0-9;¥/?:¥@&=+¥$,%#]+/);
	for(i in matches){
		str = str.replace(matches[i], '<a href="' + matches[i] + '" target="_blank">' + matches[i] +'</a>');
	}
	return str;
}

function replaceLinkEx(str){
	// urlをリンクに置き換える
	matches = str.match(/https?:\/\/[-_.!~*¥'()a-zA-Z0-9;¥/?:¥@&=+¥$,%#]+/g);
	for(i in matches){
		str = str.replace(matches[i], '<a href="' + matches[i] + '" target="_blank">' + matches[i] +'</a>');
	}
	// @usernameをusernameのアカウントページへのリンクに置き換える
	matches = str.match(/@[a-zA-Z_\-0-9]+/g);
	for(i in matches){
		if( i != "index"){
			link = '<a href="" screen_name="' + matches[i].replace("@","") + '" class="account-link">' + matches[i] +'</a>';
			str = str.replace(matches[i], link);
		}
	}
	return str;
}
